<?php
//--------------------------------------------------
//	Filename: function_like.php
//--------------------------------------------------
// Information:
// All the like-function is listed here. 
//--------------------------------------------------
if(!defined('IN_INDEX'))
{
	printError("ACCESS DENIED", "This page is hidden.");
	exit;
}

function count_numberOfPersons_like($owner_id, $post_id){
	global $db;
	
	$sql = "SELECT COUNT(*) AS total FROM tbl_like WHERE post_type='training' AND owner_id=".$owner_id." AND post_id=".$post_id.""; 
	if(!$result = $db->sql_query($sql))
	{
		printError("SQL ERROR", mysql_error($sql));
	}
	 
	$row = $db->sql_fetchrow($result);
	return $row['total'];
}

function count_numberOfPersons_like_comment($owner_id, $post_id, $comment_id){
	global $db;
	
	$sql = "SELECT COUNT(*) AS total FROM tbl_like WHERE post_type='comment' AND owner_id=".$owner_id." AND post_id=".$post_id." AND comment_id=$comment_id"; 
	if(!$result = $db->sql_query($sql))
	{
		printError("SQL ERROR", mysql_error($sql));
	}
	 
	$row = $db->sql_fetchrow($result);
	return $row['total'];
}


function is_like($owner_id, $user_id, $post_id){
	global $db;
	
	$sql = "SELECT * FROM tbl_like WHERE post_type='training' AND owner_id=".$owner_id." AND post_id=".$post_id." AND user_id=".$user_id;
	if(!$result = $db->sql_query($sql))
	{
		printError("SQL ERROR", mysql_error($sql));
	}
	$row = mysql_num_rows($result);
	
	return $row > 0 ? true:false;
}

function is_like_comment($owner_id, $user_id, $post_id, $comment_id){
	global $db;
	
	$sql = "SELECT * FROM tbl_like WHERE post_type='comment' AND owner_id=".$owner_id." AND post_id=".$post_id." AND user_id=".$user_id." AND comment_id=".$comment_id;
	if(!$result = $db->sql_query($sql))
	{
		printError("SQL ERROR", mysql_error($sql));
	}
	$row = mysql_num_rows($result);
	
	return $row > 0 ? true:false;
}